usage.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { useParams } from 'common'
  2. import { useRouter } from 'next/router'
  3. import { useEffect } from 'react'
  4. import DefaultLayout from '@/components/layouts/DefaultLayout'
  5. import SettingsLayout from '@/components/layouts/ProjectSettingsLayout/SettingsLayout'
  6. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  7. import type { NextPageWithLayout } from '@/types'
  8. const ProjectBillingUsage: NextPageWithLayout = () => {
  9. // This component is only used for redirects, as nextjs cant redirect based on hash
  10. const router = useRouter()
  11. const { ref } = useParams()
  12. const { data: organization } = useSelectedOrganizationQuery()
  13. const hash = router.asPath.split('#')[1]
  14. const route = router.route
  15. useEffect(() => {
  16. if (!organization) return
  17. let redirectUrl
  18. if (['cpu', 'ram', 'disk_io'].includes(hash)) {
  19. redirectUrl = `/project/${ref}/settings/infrastructure#${hash}`
  20. } else {
  21. redirectUrl = `/org/${organization.slug}/usage?projectRef=${ref}`
  22. }
  23. router.push(redirectUrl)
  24. }, [hash, route, organization, ref, router])
  25. return null
  26. }
  27. ProjectBillingUsage.getLayout = (page) => (
  28. <DefaultLayout>
  29. <SettingsLayout title="usage">{page}</SettingsLayout>
  30. </DefaultLayout>
  31. )
  32. export default ProjectBillingUsage